package shortlink.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import shortlink.common.convention.result.Result;
import shortlink.remote.ShortLinkRemoteService;
import shortlink.remote.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import shortlink.remote.dto.req.ShortLinkGroupStatsReqDTO;
import shortlink.remote.dto.req.ShortLinkStatsAccessRecordReqDTO;
import shortlink.remote.dto.req.ShortLinkStatsReqDTO;
import shortlink.remote.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import shortlink.remote.dto.resp.ShortLinkStatsRespDTO;

@RestController
@RequiredArgsConstructor
public class ShortLinkStatsController {

    private final ShortLinkRemoteService shortLinkRemoteService;
    /*根据短链接获取指定之间内的监控数据*/
    @GetMapping("/api/short-link/admin/linkstats/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam) {
        return shortLinkRemoteService.oneShortLinkStats(requestParam.getFullShortUrl(),
                requestParam.getGid(),
                requestParam.getEnableStatus(),
                requestParam.getStartDate(),
                requestParam.getEndDate());
    }
    /*根据短链接分组获取指定之间内的监控数据*/
    @GetMapping("/api/short-link/admin/linkstats/groupstats")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO requestParam) {
        return shortLinkRemoteService.groupShortLinkStats(requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate());
    }
    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/linkstats/statslogs")
    public Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
        return shortLinkRemoteService.shortLinkStatsAccessRecord(requestParam.getFullShortUrl(),
                requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate(),
                requestParam.getEnableStatus(),
                requestParam.getCurrent(),
                requestParam.getSize());
    }
    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/linkstats/groupstatslogs")
    public Result<Page<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        return shortLinkRemoteService.groupShortLinkStatsAccessRecord( requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate(),
                requestParam.getCurrent(),
                requestParam.getSize());
    }
}
